package homework_6.read_1;
import java.io.*;
import java.net.*;

public class Server {
    private Socket socket;
    public InputStream in;

    public Server(int port) {
        try {
            ServerSocket ss = new ServerSocket(port);
            System.out.println("等待接收数据...");
            socket = ss.accept();
            in = socket.getInputStream();
            byte[] b = new byte[8];
            int len;
            while ((len = in.read(b)) != -1) {
                String str = new String(b, 0, len);
                System.out.println(str);
            }
            ss.close();
        }
        catch (IOException e) {
            System.out.println("Server constructor IOEx: " + e);
        }
    }

    public static void main(String[] args) {
        new Server(8001);
    }
}

